package com.zsc.edu.gateway.modules.iot.device.repo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
import com.zsc.edu.gateway.modules.iot.device.query.DeviceQuery;
import com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @author zhuang
 */
public interface DeviceRepository extends BaseMapper<Device> {
    @Select("select * from iot_device where name=#{name}")
    Device findByName(@Param("name") String name);

    DeviceVo findById(@Param("id") Long id);

    @Select("select * from iot_device where client_id=#{clientId} and state=#{status} and online=#{online}")
    Device findByClientIdAndStateAndOnline(@Param("clientId") String clientId,
                                           @Param("status") Device.Status status,
                                           @Param("online") Boolean online);

    @Select("select * from iot_device where client_id=#{clientId}")
    Device findByClientId(@Param("clientId") String clientId);

    List<Device> selectListByName(@Param("name") String name);

    IPage<Device> selectPageByConditions(Page<Device> page, @Param("query") DeviceQuery query);
}
